/*
 * =====================================================================================
 *
 *       Filename:  Connection.cpp
 *
 *    Description:
 *
 *        Version:  1.0
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Fang Dongheng (fndisme), fndisme@163.com
 *   Organization:
 *
 * =====================================================================================
 */
#include "net/Connection.h"
#include <iostream>
#include <boost/log/trivial.hpp>
namespace FakeWeiXin {
Connection::~Connection() {}
Connection::Connection(boost::asio::io_service& ioService)
    : m_ioService(ioService),m_socket(ioService) {}
bool Connection::syncConnect(const std::string& address, int16_t port) {
  boost::system::error_code ec;
  auto addr = boost::asio::ip::address::from_string(address, ec);
  if (ec) {
    BOOST_LOG_TRIVIAL(info) << "build address failed" << ec.message() << " "
                            << address;
    return false;
  }
	boost::asio::ip::tcp::endpoint endpoint(addr, port);
	m_socket.connect(endpoint, ec);
	if(ec) {
    BOOST_LOG_TRIVIAL(info) << "count not connect to" << ec.message() << " "
                            << address << " " << port;
		return false;
	}
  return true;
}
}

